﻿namespace WMS6.Web.TransportManagement
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.OutboundServiceRef;
    using WMS6.Web.TransportMgtServiceRef;

    public class DeliveryOrder : BasePage
    {
        protected HtmlInputButton btnAction;
        protected Button btnAddDetail;
        protected Button btnCopy;
        protected Button btnDelete;
        protected Button btnDeleteDetail;
        protected Button btnGoBack;
        protected Button btnInputSO;
        protected Button btnNew;
        protected Button btnSave;
        protected CheckBox chbDIsWeekEndWork;
        protected CheckBox chbPIsWeekEndWork;
        protected CheckBox chePriority;
        protected DropDownList ddlBillingType;
        protected DropDownList ddlDeliveryOrderStatue;
        protected DropDownList ddlDeliveryOrderType;
        protected DropDownList ddlPaymentType;
        protected DropDownList ddlPickupType;
        protected DropDownList ddlTransferType;
        protected HtmlForm F8011;
        protected GridView gvDeliveryOrderDetail;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnCopy;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnDeliveryOrderID;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnInportValue;
        protected HtmlInputHidden hdnLineID;
        protected HtmlInputHidden hdnPageQty;
        protected HtmlInputHidden hdnPageType;
        protected Label lblBillingType;
        protected Label lblCAddress;
        protected Label lblCarrierID;
        protected Label lblCCity;
        protected Label lblCContact1;
        protected Label lblCContact2;
        protected Label lblCCountry;
        protected Label lblCEmail1;
        protected Label lblCEmail2;
        protected Label lblCFax1;
        protected Label lblCFax2;
        protected Label lblCName;
        protected Label lblCProvince;
        protected Label lblCreatedBy;
        protected Label lblCreatedDate;
        protected Label lblCTel1;
        protected Label lblCTel2;
        protected Label lblCustomerID;
        protected Label lblCZip;
        protected Label lblDAddress;
        protected Label lblDCity;
        protected Label lblDContact;
        protected Label lblDCountry;
        protected Label lblDeliveryLocID;
        protected Label lblDeliveryOrderID;
        protected Label lblDeliveryOrderStatue;
        protected Label lblDeliveryOrderType;
        protected Label lblDEmail;
        protected Label lblDeparture;
        protected Label lblDestination;
        protected Label lblDFax;
        protected Label lblDProvince;
        protected Label lblDTel;
        protected Label lblDZip;
        protected Label lblExpectArrivalDate;
        protected Label lblExternOrderID;
        protected Label lblExternOrderID2;
        protected Label lblLocAddrID;
        protected Label lblMsg;
        protected Label lblOwner;
        protected Label lblOwnerID;
        protected Label lblPAddress;
        protected Label lblPaymentType;
        protected Label lblPCity;
        protected Label lblPContact;
        protected Label lblPCountry;
        protected Label lblPEmail;
        protected Label lblPFax;
        protected Label lblPickupType;
        protected Label lblPProvince;
        protected Label lblPTel;
        protected Label lblPZip;
        protected Label lblRemark;
        protected Label lblRequestedShipDate;
        protected Label lblTotalCube;
        protected Label lblTotalQty;
        protected Label lblTotalWeight;
        protected Label lblTransferType;
        protected Label lblUdf04;
        protected Label lblUdf09;
        protected Label lblUdf1;
        protected Label lblUdf10;
        protected Label lblUdf2;
        protected Label lblUdf3;
        protected Label lblUdf5;
        protected Label lblUdf6;
        protected Label lblUdf7;
        protected Label lblUdf8;
        protected LinkButton lnkbtnImportShippingOrder;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected Label one4;
        protected Label one5;
        protected Label one6;
        protected ScriptManager ScriptManager1;
        protected HtmlTableCell tdlnkbtnImportShippingOrder;
        protected TextBox txtCAddress;
        protected TextBox txtCarrierID;
        protected TextBox txtCCity;
        protected TextBox txtCContanct1;
        protected TextBox txtCContanct2;
        protected TextBox txtCCountry;
        protected TextBox txtCEmail1;
        protected TextBox txtCEmail2;
        protected TextBox txtCFax1;
        protected TextBox txtCFax2;
        protected TextBox txtCProvince;
        protected TextBox txtCreatedBy;
        protected TextBox txtCreatedDate;
        protected TextBox txtCTel1;
        protected TextBox txtCTel2;
        protected TextBox txtCustomerID;
        protected TextBox txtCustomerName;
        protected TextBox txtCZip;
        protected TextBox txtDAddress;
        protected TextBox txtDCity;
        protected TextBox txtDContact;
        protected TextBox txtDCountry;
        protected TextBox txtDeliveryLocID;
        protected TextBox txtDeliveryOrderID;
        protected TextBox txtDEmail;
        protected TextBox txtDeparture;
        protected TextBox txtDestination;
        protected TextBox txtDFax;
        protected TextBox txtDProvince;
        protected TextBox txtDTel;
        protected TextBox txtDZip;
        protected TextBox txtExpectArrivalDate;
        protected TextBox txtExternOrderID;
        protected TextBox txtExternOrderID2;
        protected TextBox txtLocAddrID;
        protected TextBox txtOwnerID;
        protected TextBox txtPAddress;
        protected TextBox txtPCity;
        protected TextBox txtPContact;
        protected TextBox txtPCountry;
        protected TextBox txtPEmail;
        protected TextBox txtPFax;
        protected TextBox txtPProvince;
        protected TextBox txtPTel;
        protected TextBox txtPZip;
        protected TextBox txtRemark;
        protected TextBox txtRequestedShipDate;
        protected TextBox txtTotalCube;
        protected TextBox txtTotalQty;
        protected TextBox txtTotalWeight;
        protected TextBox txtUdf1;
        protected TextBox txtUdf10;
        protected TextBox txtUdf2;
        protected TextBox txtUdf3;
        protected TextBox txtUdf4;
        protected TextBox txtUdf5;
        protected TextBox txtUdf6;
        protected TextBox txtUdf7;
        protected TextBox txtUdf8;
        protected TextBox txtUdf9;
        protected UpdatePanel up1;

        protected void btnAddDetail_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.hdnLineID.Value))
                {
                    this.InsertDeliveryOrder();
                    this.hdnLineID.Value = "10";
                }
                base.Response.Redirect(string.Format("DeliveryOrderDetail.aspx?from={0}&ID={1}&SeqNO={2}&OwnerID={3}", new object[] { base.UrlEncode(this.hdnFrom.Value), base.UrlEncode(this.txtDeliveryOrderID.Text.Trim()), base.UrlEncode(this.hdnLineID.Value), base.UrlEncode(this.txtOwnerID.Text.Trim()), true }));
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtDeliveryOrderID.Text = "";
            this.btnAddDetail.Visible = false;
            this.btnDeleteDetail.Visible = false;
            this.ddlDeliveryOrderStatue.SelectedValue = "New";
            this.hdnFlag.Value = "0";
            this.hdnCopy.Value = "1";
            this.lblMsg.Text = base.GetGlobalMsgResource("F8100_007");
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtDeliveryOrderID.Text.Trim()))
            {
                try
                {
                    if (this.ddlDeliveryOrderStatue.SelectedValue.ToString().ToUpper() != "NEW")
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F8100_006");
                    }
                    else
                    {
                        List<string> deliveryOrderIDs = new List<string> {
                            this.txtDeliveryOrderID.Text.Trim()
                        };
                        this.lblMsg.Text = TransportMgtServiceClientProxy.GetInstance().DeleteDeliveryOrder(deliveryOrderIDs) + base.GetGlobalMsgResource("C006");
                        this.btnSave.Enabled = false;
                        this.btnDelete.Enabled = false;
                        this.btnCopy.Enabled = false;
                        base.DataEntityViewState = null;
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("C007") + ex.Message;
                }
            }
        }

        protected void btnDeleteDetail_Click(object sender, EventArgs e)
        {
            List<string> deliveryOrderID = base.GetSelectedIDsInGridView(this.gvDeliveryOrderDetail, "DELIVERYORDERID");
            List<string> lineID = base.GetSelectedIDsInGridView(this.gvDeliveryOrderDetail, "LINEID");
            if ((deliveryOrderID.Count > 0) && (lineID.Count > 0))
            {
                try
                {
                    this.lblMsg.Text = TransportDetailMgtServiceClientProxy.GetInstance().DeleteDeliveryOrderDetailInfo(deliveryOrderID, lineID) + base.GetGlobalMsgResource("C006");
                    this.SetDeliveryOrderInfo2Form();
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',6,6);</script>", false);
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("C012") + ex.Message;
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',6,6);</script>", false);
                this.lblMsg.Text = base.GetGlobalMsgResource("C008");
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("DeliveryOrderQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("DeliveryOrderList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnInputSO_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtExternOrderID.Text.Trim()))
            {
                this.ViewState["IsInport"] = "1";
                this.InputFromOrder();
            }
            this.txtExternOrderID.Focus();
            this.hdnPageType.Value = "0";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtRequestedShipDate.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F8100_001");
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,6);</script>", false);
            }
            else if (string.IsNullOrEmpty(this.txtExpectArrivalDate.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F8100_002");
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,6);</script>", false);
            }
            else if (string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F8100_003");
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,6);</script>", false);
            }
            else if (string.IsNullOrEmpty(this.txtLocAddrID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F8100_004");
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,6);</script>", false);
            }
            else if (string.IsNullOrEmpty(this.txtDeliveryLocID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F8100_005");
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,6);</script>", false);
            }
            else
            {
                if ((this.ViewState["IsInport"] != null) && (this.ViewState["IsInport"].ToString() == "1"))
                {
                    this.UpdateDeliveryOrder();
                    this.ViewState["IsInport"] = null;
                }
                else if (this.hdnFlag.Value == "1")
                {
                    this.UpdateDeliveryOrder();
                }
                else
                {
                    this.InsertDeliveryOrder();
                }
                if (this.hdnCopy.Value == "1")
                {
                    this.SetDeliveryOrderInfo2Form();
                }
                this.hdnPageQty.Value = "0";
                this.btnAddDetail.Visible = true;
                this.btnDeleteDetail.Visible = true;
            }
        }

        protected void gvDeliveryOrderDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F8011", this.gvDeliveryOrderDetail);
        }

        protected void gvDeliveryOrderDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = this.gvDeliveryOrderDetail.PageIndex * this.gvDeliveryOrderDetail.PageSize;
                e.Row.Cells[1].Text = ((e.Row.RowIndex + 1) + i).ToString();
            }
        }

        private void InputFromOrder()
        {
            try
            {
                string createdBy = base.UserInfo.UserID;
                string deliveryOrderID = TransportMgtServiceClientProxy.GetInstance().ImportFormShippingOrder(this.txtExternOrderID.Text.Trim(), this.txtDeliveryOrderID.Text.Trim());
                this.txtDeliveryOrderID.Text = deliveryOrderID;
                this.hdnDeliveryOrderID.Value = deliveryOrderID;
                this.lblMsg.Text = deliveryOrderID + base.GetGlobalMsgResource("F8100_008");
                this.SetDeliveryOrderInfo2Form();
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F8100_009") + ex.Message;
            }
        }

        private void InsertDeliveryOrder()
        {
            try
            {
                if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F8100_016");
                    this.txtOwnerID.Focus();
                }
                else
                {
                    DeliveryOrderInfo deliveryOrderInfo = new DeliveryOrderInfo();
                    if (this.hdnCopy.Value == "1")
                    {
                        if (base.DataEntityViewState != null)
                        {
                            deliveryOrderInfo = base.DataEntityViewState as DeliveryOrderInfo;
                            deliveryOrderInfo.DeliveryOrderID = "";
                            deliveryOrderInfo.Status = "New";
                            if ((deliveryOrderInfo.DeliveryOrderDetailInfos != null) && (deliveryOrderInfo.DeliveryOrderDetailInfos.Count > 0))
                            {
                                for (int i = 0; i < deliveryOrderInfo.DeliveryOrderDetailInfos.Count; i++)
                                {
                                    deliveryOrderInfo.DeliveryOrderDetailInfos[i].DeliveryOrderID = "";
                                    deliveryOrderInfo.DeliveryOrderDetailInfos[i].LineID = (i + 1) * 10;
                                    deliveryOrderInfo.DeliveryOrderDetailInfos[i].LoadingQty = 0.0M;
                                    deliveryOrderInfo.DeliveryOrderDetailInfos[i].RejectedQty = 0.0M;
                                    deliveryOrderInfo.DeliveryOrderDetailInfos[i].CreatedBy = base.UserInfo.UserID;
                                }
                            }
                        }
                    }
                    else
                    {
                        deliveryOrderInfo = this.SetDeliveryOrderInfo(ref deliveryOrderInfo);
                    }
                    deliveryOrderInfo.CreatedBy = base.UserInfo.UserID;
                    DateTime tempDate = DateTime.Now;
                    if (DateTime.TryParse(this.txtRequestedShipDate.Text.Trim(), out tempDate))
                    {
                        deliveryOrderInfo.RequestedShipDate = Convert.ToDateTime(this.txtRequestedShipDate.Text.Trim());
                    }
                    else
                    {
                        deliveryOrderInfo.RequestedShipDate = DateTime.Now;
                    }
                    if (DateTime.TryParse(this.txtExpectArrivalDate.Text.Trim(), out tempDate))
                    {
                        deliveryOrderInfo.ExpectArrivalDate = Convert.ToDateTime(this.txtExpectArrivalDate.Text.Trim());
                    }
                    else
                    {
                        deliveryOrderInfo.ExpectArrivalDate = DateTime.Now;
                    }
                    string deliveryOrderID = TransportMgtServiceClientProxy.GetInstance().InsertDeliveryOrderInfo(deliveryOrderInfo);
                    deliveryOrderInfo.DeliveryOrderID = deliveryOrderID;
                    this.lblMsg.Text = deliveryOrderID + base.GetGlobalMsgResource("C004");
                    this.txtDeliveryOrderID.Text = deliveryOrderID;
                    base.DataEntityViewState = deliveryOrderInfo;
                    this.hdnFlag.Value = "1";
                    this.hdnDeliveryOrderID.Value = deliveryOrderID;
                    this.txtDeliveryOrderID.Enabled = false;
                    if ((deliveryOrderInfo.DeliveryOrderDetailInfos != null) && (deliveryOrderInfo.DeliveryOrderDetailInfos.Count > 0))
                    {
                        this.hdnLineID.Value = (deliveryOrderInfo.DeliveryOrderDetailInfos[deliveryOrderInfo.DeliveryOrderDetailInfos.Count - 1].LineID + 10).ToString();
                    }
                    else
                    {
                        this.hdnLineID.Value = "10";
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C005") + ex.Message;
            }
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlDeliveryOrderType, "DeliveryType");
            base.BindData2DDLBySysCode(this.ddlDeliveryOrderStatue, "DeliveryOrderStatus");
            base.BindData2DDLBySysCode(this.ddlPickupType, "PickupType");
            base.BindData2DDLBySysCode(this.ddlTransferType, "TransportMode");
            base.BindData2DDLBySysCode(this.ddlPaymentType, "PaymentType");
            base.BindData2DDLBySysCode(this.ddlBillingType, "TransportBillingType");
            this.txtCreatedBy.Text = base.UserInfo.UserID;
            this.txtCreatedDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnDeliveryOrderID.Value = base.Request.QueryString["ID"].ToString();
                this.SetDeliveryOrderInfo2Form();
                this.hdnFlag.Value = "1";
            }
            else
            {
                base.SetDefaultOwner(this.txtOwnerID);
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["detail"]))
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',6,6);</script>", false);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private DeliveryOrderInfo SetDeliveryOrderInfo(ref DeliveryOrderInfo deliveryOrderInfo)
        {
            decimal tempDec = 0.0M;
            DateTime tempDate = DateTime.Now;
            deliveryOrderInfo.DeliveryOrderID = this.txtDeliveryOrderID.Text.Trim();
            deliveryOrderInfo.ExternOrderID = this.txtExternOrderID.Text.Trim();
            deliveryOrderInfo.ExternOrderId2 = this.txtExternOrderID2.Text.Trim();
            deliveryOrderInfo.ActualShipDate = tempDate;
            deliveryOrderInfo.OwnerID = this.txtOwnerID.Text.Trim();
            deliveryOrderInfo.DeliveryOrderType = this.ddlDeliveryOrderType.SelectedValue;
            deliveryOrderInfo.Status = this.ddlDeliveryOrderStatue.SelectedValue;
            deliveryOrderInfo.Departure = this.txtDeparture.Text.Trim();
            deliveryOrderInfo.Destination = this.txtDestination.Text.Trim();
            deliveryOrderInfo.PickupType = this.ddlPickupType.SelectedValue;
            deliveryOrderInfo.TransferType = this.ddlTransferType.SelectedValue;
            if (decimal.TryParse(this.txtTotalQty.Text.Trim(), out tempDec))
            {
                deliveryOrderInfo.TotalQty = decimal.Parse(this.txtTotalQty.Text.Trim());
            }
            else
            {
                deliveryOrderInfo.TotalQty = tempDec;
            }
            if (decimal.TryParse(this.txtTotalWeight.Text.Trim(), out tempDec))
            {
                deliveryOrderInfo.TotalWeight = decimal.Parse(this.txtTotalWeight.Text.Trim());
            }
            else
            {
                deliveryOrderInfo.TotalWeight = tempDec;
            }
            if (decimal.TryParse(this.txtTotalCube.Text.Trim(), out tempDec))
            {
                deliveryOrderInfo.TotalCube = decimal.Parse(this.txtTotalCube.Text.Trim());
            }
            else
            {
                deliveryOrderInfo.TotalCube = tempDec;
            }
            deliveryOrderInfo.PaymentType = this.ddlPaymentType.SelectedValue;
            deliveryOrderInfo.CarrierID = this.txtCarrierID.Text.Trim();
            deliveryOrderInfo.Priority = this.chePriority.Checked ? "Y" : "N";
            deliveryOrderInfo.BillingType = this.ddlBillingType.SelectedValue;
            deliveryOrderInfo.CustomerID = this.txtCustomerID.Text.Trim();
            deliveryOrderInfo.CName = this.txtCustomerName.Text.Trim();
            deliveryOrderInfo.CCity = this.txtCCity.Text.Trim();
            deliveryOrderInfo.CProvince = this.txtCProvince.Text.Trim();
            deliveryOrderInfo.CContact1 = this.txtCContanct1.Text.Trim();
            deliveryOrderInfo.CContact2 = this.txtCContanct2.Text.Trim();
            deliveryOrderInfo.CZip = this.txtCZip.Text.Trim();
            deliveryOrderInfo.CCountry = this.txtCCountry.Text.Trim();
            deliveryOrderInfo.CTel1 = this.txtCTel1.Text.Trim();
            deliveryOrderInfo.CTel2 = this.txtCTel2.Text.Trim();
            deliveryOrderInfo.CAddress = this.txtCAddress.Text.Trim();
            deliveryOrderInfo.CFax1 = this.txtCFax1.Text.Trim();
            deliveryOrderInfo.CFax2 = this.txtCFax2.Text.Trim();
            deliveryOrderInfo.CEmail1 = this.txtCEmail1.Text.Trim();
            deliveryOrderInfo.CEmail2 = this.txtCEmail2.Text.Trim();
            deliveryOrderInfo.PickupLocID = this.txtLocAddrID.Text.Trim();
            deliveryOrderInfo.PAddress = this.txtPAddress.Text.Trim();
            deliveryOrderInfo.PCountry = this.txtPCountry.Text.Trim();
            deliveryOrderInfo.PProvince = this.txtPProvince.Text.Trim();
            deliveryOrderInfo.PCity = this.txtPCity.Text.Trim();
            deliveryOrderInfo.PContact = this.txtPContact.Text.Trim();
            deliveryOrderInfo.PTel = this.txtPTel.Text.Trim();
            deliveryOrderInfo.PZip = this.txtPZip.Text.Trim();
            deliveryOrderInfo.PFax = this.txtPFax.Text.Trim();
            deliveryOrderInfo.PEmail = this.txtPEmail.Text.Trim();
            deliveryOrderInfo.PIsWeekedWork = this.chbPIsWeekEndWork.Checked ? "Y" : "N";
            deliveryOrderInfo.DeliveryLocID = this.txtDeliveryLocID.Text.Trim();
            deliveryOrderInfo.DAddress = this.txtDAddress.Text.Trim();
            deliveryOrderInfo.DCountry = this.txtDCountry.Text.Trim();
            deliveryOrderInfo.DProvince = this.txtDProvince.Text.Trim();
            deliveryOrderInfo.DCity = this.txtDCity.Text.Trim();
            deliveryOrderInfo.DContact = this.txtDContact.Text.Trim();
            deliveryOrderInfo.DTel = this.txtDTel.Text.Trim();
            deliveryOrderInfo.DZip = this.txtDZip.Text.Trim();
            deliveryOrderInfo.DFax = this.txtDFax.Text.Trim();
            deliveryOrderInfo.DEmail = this.txtDEmail.Text.Trim();
            deliveryOrderInfo.DIsWeekedWork = this.chbDIsWeekEndWork.Checked ? "Y" : "N";
            deliveryOrderInfo.Udf1 = this.txtUdf1.Text.Trim();
            deliveryOrderInfo.Udf2 = this.txtUdf2.Text.Trim();
            deliveryOrderInfo.Udf3 = this.txtUdf3.Text.Trim();
            deliveryOrderInfo.Udf4 = this.txtUdf4.Text.Trim();
            deliveryOrderInfo.Udf5 = this.txtUdf5.Text.Trim();
            deliveryOrderInfo.Udf6 = this.txtUdf6.Text.Trim();
            deliveryOrderInfo.Udf7 = this.txtUdf7.Text.Trim();
            deliveryOrderInfo.Udf8 = this.txtUdf8.Text.Trim();
            deliveryOrderInfo.Udf9 = this.txtUdf9.Text.Trim();
            deliveryOrderInfo.Udf10 = this.txtUdf10.Text.Trim();
            deliveryOrderInfo.CreatedDate = DateTime.Now;
            deliveryOrderInfo.StartLocAddr = "";
            deliveryOrderInfo.EndLocAddr = "";
            deliveryOrderInfo.IsActive = "Y";
            return deliveryOrderInfo;
        }

        private void SetDeliveryOrderInfo2Form()
        {
            try
            {
                string DeliveryOrderID = this.hdnDeliveryOrderID.Value.ToString();
                DeliveryOrderInfo deliveryOrderInfo = TransportMgtServiceClientProxy.GetInstance().GetDeliveryOrderInfoByID(DeliveryOrderID);
                base.DataEntityViewState = deliveryOrderInfo;
                if (deliveryOrderInfo != null)
                {
                    this.txtDeliveryOrderID.Text = deliveryOrderInfo.DeliveryOrderID;
                    this.txtDeliveryOrderID.Enabled = false;
                    this.txtExternOrderID.Text = deliveryOrderInfo.ExternOrderID;
                    this.txtExternOrderID2.Text = deliveryOrderInfo.ExternOrderId2;
                    this.txtRequestedShipDate.Text = base.GetPreferenceShortDate(deliveryOrderInfo.RequestedShipDate);
                    this.txtOwnerID.Text = deliveryOrderInfo.OwnerID;
                    this.ddlDeliveryOrderType.SelectedValue = deliveryOrderInfo.DeliveryOrderType;
                    this.ddlDeliveryOrderStatue.SelectedValue = deliveryOrderInfo.Status;
                    this.txtExpectArrivalDate.Text = base.GetPreferenceShortDate(deliveryOrderInfo.ExpectArrivalDate);
                    this.txtDeparture.Text = deliveryOrderInfo.Departure;
                    this.txtDestination.Text = deliveryOrderInfo.Destination;
                    this.ddlPickupType.SelectedValue = deliveryOrderInfo.PickupType;
                    this.ddlTransferType.SelectedValue = deliveryOrderInfo.TransferType;
                    this.txtTotalQty.Text = base.GetPreferenceDigit(deliveryOrderInfo.TotalQty);
                    this.txtTotalWeight.Text = base.GetPreferenceDigit(deliveryOrderInfo.TotalWeight);
                    this.txtTotalCube.Text = base.GetPreferenceDigit(deliveryOrderInfo.TotalCube);
                    this.ddlPaymentType.SelectedValue = deliveryOrderInfo.PaymentType;
                    this.txtCarrierID.Text = deliveryOrderInfo.CarrierID;
                    this.ddlBillingType.SelectedValue = deliveryOrderInfo.BillingType;
                    this.chePriority.Checked = deliveryOrderInfo.Priority == "Y";
                    this.txtCustomerID.Text = deliveryOrderInfo.CustomerID;
                    this.txtCustomerName.Text = deliveryOrderInfo.CName;
                    this.txtCCity.Text = deliveryOrderInfo.CCity;
                    this.txtCProvince.Text = deliveryOrderInfo.CProvince;
                    this.txtCContanct1.Text = deliveryOrderInfo.CContact1;
                    this.txtCContanct2.Text = deliveryOrderInfo.CContact2;
                    this.txtCZip.Text = deliveryOrderInfo.CZip;
                    this.txtCCountry.Text = deliveryOrderInfo.CCountry;
                    this.txtCTel1.Text = deliveryOrderInfo.CTel1;
                    this.txtCTel2.Text = deliveryOrderInfo.CTel2;
                    this.txtCAddress.Text = deliveryOrderInfo.CAddress;
                    this.txtCFax1.Text = deliveryOrderInfo.CFax1;
                    this.txtCFax2.Text = deliveryOrderInfo.CFax2;
                    this.txtCEmail1.Text = deliveryOrderInfo.CEmail1;
                    this.txtCEmail2.Text = deliveryOrderInfo.CEmail2;
                    this.txtLocAddrID.Text = deliveryOrderInfo.PickupLocID;
                    this.txtPAddress.Text = deliveryOrderInfo.PAddress;
                    this.txtPCountry.Text = deliveryOrderInfo.PCountry;
                    this.txtPProvince.Text = deliveryOrderInfo.PProvince;
                    this.txtPCity.Text = deliveryOrderInfo.PCity;
                    this.txtPContact.Text = deliveryOrderInfo.PContact;
                    this.txtPTel.Text = deliveryOrderInfo.PTel;
                    this.txtPZip.Text = deliveryOrderInfo.PZip;
                    this.txtPFax.Text = deliveryOrderInfo.PFax;
                    this.txtPEmail.Text = deliveryOrderInfo.PEmail;
                    this.chbPIsWeekEndWork.Checked = deliveryOrderInfo.PIsWeekedWork == "Y";
                    this.txtDeliveryLocID.Text = deliveryOrderInfo.DeliveryLocID;
                    this.txtDAddress.Text = deliveryOrderInfo.DAddress;
                    this.txtDCountry.Text = deliveryOrderInfo.DCountry;
                    this.txtDProvince.Text = deliveryOrderInfo.DProvince;
                    this.txtDCity.Text = deliveryOrderInfo.DCity;
                    this.txtDContact.Text = deliveryOrderInfo.DContact;
                    this.txtDTel.Text = deliveryOrderInfo.DTel;
                    this.txtDZip.Text = deliveryOrderInfo.DZip;
                    this.txtDFax.Text = deliveryOrderInfo.DFax;
                    this.txtDEmail.Text = deliveryOrderInfo.DEmail;
                    this.chbPIsWeekEndWork.Checked = deliveryOrderInfo.DIsWeekedWork == "Y";
                    this.txtUdf1.Text = deliveryOrderInfo.Udf1;
                    this.txtUdf2.Text = deliveryOrderInfo.Udf2;
                    this.txtUdf3.Text = deliveryOrderInfo.Udf3;
                    this.txtUdf4.Text = deliveryOrderInfo.Udf4;
                    this.txtUdf5.Text = deliveryOrderInfo.Udf5;
                    this.txtUdf6.Text = deliveryOrderInfo.Udf6;
                    this.txtUdf7.Text = deliveryOrderInfo.Udf7;
                    this.txtUdf8.Text = deliveryOrderInfo.Udf8;
                    this.txtUdf9.Text = deliveryOrderInfo.Udf9;
                    this.txtUdf10.Text = deliveryOrderInfo.Udf10;
                    this.txtCreatedBy.Text = deliveryOrderInfo.CreatedBy;
                    this.txtCreatedDate.Text = base.GetPreferenceShortDate(deliveryOrderInfo.CreatedDate);
                    if ((deliveryOrderInfo.DeliveryOrderDetailInfos != null) && (deliveryOrderInfo.DeliveryOrderDetailInfos.Count > 0))
                    {
                        this.hdnLineID.Value = (deliveryOrderInfo.DeliveryOrderDetailInfos[deliveryOrderInfo.DeliveryOrderDetailInfos.Count - 1].LineID + 10).ToString();
                    }
                    else
                    {
                        this.hdnLineID.Value = "10";
                    }
                    base.BindData2GridView(this.gvDeliveryOrderDetail, deliveryOrderInfo.DeliveryOrderDetailInfos);
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        protected void txtCustomerID_TextChanged(object sender, EventArgs e)
        {
            CustomerInfo customerInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtCustomerID.Text.Trim(), "CUSTOMER") as CustomerInfo;
            if (!((customerInfo == null) || string.IsNullOrEmpty(customerInfo.CustomerID)))
            {
                this.txtCustomerName.Text = customerInfo.Company;
                this.txtCCity.Text = customerInfo.City;
                this.txtCProvince.Text = customerInfo.State;
                this.txtCContanct1.Text = customerInfo.Contact1;
                this.txtCContanct2.Text = customerInfo.Contact2;
                this.txtCZip.Text = customerInfo.Zip;
                this.txtCCountry.Text = customerInfo.Country;
                this.txtCTel1.Text = customerInfo.Phone1;
                this.txtCTel2.Text = customerInfo.Phone2;
                this.txtCAddress.Text = customerInfo.Address;
                this.txtCFax1.Text = customerInfo.Fax1;
                this.txtCFax2.Text = customerInfo.Fax2;
                this.txtCEmail1.Text = customerInfo.Email1;
                this.txtCEmail2.Text = customerInfo.Email2;
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,6);</script>", false);
            this.txtCustomerID.Focus();
            this.hdnPageType.Value = "0";
        }

        protected void txtDeliveryLocID_TextChanged(object sender, EventArgs e)
        {
            LocAddrInfo locAddrInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtDeliveryLocID.Text.Trim(), "LOC_ADDR") as LocAddrInfo;
            if (!((locAddrInfo == null) || string.IsNullOrEmpty(locAddrInfo.LocAddrID)))
            {
                this.txtDestination.Text = locAddrInfo.LocSiteID;
                this.txtDAddress.Text = locAddrInfo.Address;
                this.txtDProvince.Text = locAddrInfo.Province;
                this.txtDCity.Text = locAddrInfo.City;
                this.txtDContact.Text = locAddrInfo.ContactName;
                this.txtDTel.Text = locAddrInfo.Telephone;
                this.txtDZip.Text = locAddrInfo.Zip;
                this.txtDFax.Text = locAddrInfo.Fax;
                this.txtDEmail.Text = locAddrInfo.Email;
                this.chbDIsWeekEndWork.Checked = locAddrInfo.IsWeekendWork == "Y";
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,6);</script>", false);
            this.txtLocAddrID.Focus();
            this.hdnPageType.Value = "0";
        }

        protected void txtExternOrderID_TextChanged(object sender, EventArgs e)
        {
            OrdersInfo ordersInfo = OutboundServiceClientProxy.GetInstance().GetOrdersInfoByOrderID(this.txtExternOrderID.Text.Trim());
            if (!((ordersInfo == null) || string.IsNullOrEmpty(ordersInfo.OrderID)))
            {
                this.txtOwnerID.Text = ordersInfo.OwnerID;
                this.txtRequestedShipDate.Text = base.GetPreferenceShortDate(ordersInfo.RequestedShipDate);
                this.ddlTransferType.SelectedValue = ordersInfo.TransportationMode;
                this.txtCarrierID.Text = ordersInfo.CarrierID;
                this.txtCustomerID.Text = ordersInfo.ConsigneeID;
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,6);</script>", false);
            this.txtExternOrderID.Focus();
            this.hdnPageType.Value = "0";
        }

        protected void txtLocAddrID_TextChanged(object sender, EventArgs e)
        {
            LocAddrInfo locAddrInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtLocAddrID.Text.Trim(), "LOC_ADDR") as LocAddrInfo;
            if (!((locAddrInfo == null) || string.IsNullOrEmpty(locAddrInfo.LocAddrID)))
            {
                this.txtDeparture.Text = locAddrInfo.LocSiteID;
                this.txtPAddress.Text = locAddrInfo.Address;
                this.txtPProvince.Text = locAddrInfo.Province;
                this.txtPCity.Text = locAddrInfo.City;
                this.txtPContact.Text = locAddrInfo.ContactName;
                this.txtPTel.Text = locAddrInfo.Telephone;
                this.txtPZip.Text = locAddrInfo.Zip;
                this.txtPFax.Text = locAddrInfo.Fax;
                this.txtPEmail.Text = locAddrInfo.Email;
                this.chbPIsWeekEndWork.Checked = locAddrInfo.IsWeekendWork == "Y";
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,6);</script>", false);
            this.txtLocAddrID.Focus();
            this.hdnPageType.Value = "0";
        }

        private void UpdateDeliveryOrder()
        {
            try
            {
                if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F8100_016");
                    this.txtOwnerID.Focus();
                }
                else
                {
                    DeliveryOrderInfo deliveryOrderInfo = base.DataEntityViewState as DeliveryOrderInfo;
                    deliveryOrderInfo = this.SetDeliveryOrderInfo(ref deliveryOrderInfo);
                    deliveryOrderInfo.UpdatedBy = base.UserInfo.UserID;
                    this.lblMsg.Text = TransportMgtServiceClientProxy.GetInstance().UpdateDeliveryOrder(deliveryOrderInfo) + base.GetGlobalMsgResource("C002");
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C003") + ex.Message;
            }
        }
    }
}

